package net.baikentools.util;

import java.io.ByteArrayInputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import net.baikentools.model.ClassEntity;
import net.baikentools.model.FieldEntity;
import net.baikentools.model.MethodEntity;
import net.baikentools.model.PropertyEntity;
import net.baikentools.model.ReverseEngineeringResult;
import net.baikentools.page.reverseengineering.ReverseEngineeringCSharp;

public class JAXBUtil {

	public static ReverseEngineeringResult read(String xmlString) {
		ReverseEngineeringResult result = null;
		try {
			JAXBContext context = JAXBContext
					.newInstance(ReverseEngineeringResult.class,
							ClassEntity.class, MethodEntity.class,
							FieldEntity.class, PropertyEntity.class);

			Unmarshaller unmarshal = context.createUnmarshaller();

			ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
					xmlString.getBytes());

			result = (ReverseEngineeringResult) unmarshal
					.unmarshal(byteArrayInputStream);
		} catch (JAXBException e) {
			throw new RuntimeException(e);
		}
		return result;

	}

}
